<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
include './controller/SO_artistController.php';
$JO["updatealbum"]= JO( array( "EN" => "Update Album","VI"=>"Cập nhật thông tin Album") );

?>
<div style="margin-left: 0px;" class="bar_720i" >
    <div style="" class="title_720i">
        <h1 style="width:696px;" class="h1i">
            <?=$JO["updatealbum"]?>
        </h1>
    </div>
    <div class="content720i">
        <table class="tbi" style="margin: 8px 0px 0px 8px;width: 696px;">
            <tr>
                <th  style="width: 40px">Key</th>
                <th style="width: 80px">Bugs</th>
                <th style="width: 200px">Subject</th>
                <th style="width: 120px">Insert</th>
                <th style="width: 120px">Update</th>
                <th class="abcdef">#</th>
            </tr>
            <tr>
                <td class="pad0"><input type="text" id="txtsekey" name="txtsekey" class="input_texti" value="" style="width: 32px"/> </td>
                <td class="pad0"><input type="text" id="txtsebugs" name="txtsebugs" class="input_texti" value="" style="width: 72px"/></td>
                <td class="pad0"><input type="text" id="txtsename" name="txtsename" class="input_texti" value="" style="width: 192px"/></td>
                <td class="pad0"><input type="text" id="" name="" value="" class="input_texti" style="width: 100px"/></td>
                <td class="pad0"><input type="text" id="" name="" value="" class="input_texti" style="width: 100px"/></td>
                <td><a id="JO_getalbum" href="javascript:void(0);" class="input_buttoni">Get</a></td>
            </tr>
        </table>
        <span id="JO_albumcontent">
        <?
        include 'SO_032_albumOBJ.php';
        ?>
        </span>
        <script>
            function initeditalbum(){
            $(".tdactionalbum").click(
                function(){
                    var nid=$($(this.parentNode).children('.tdkeyalbum')).html();
                    if($('#txtalbumkey').length){
                        if($('#txtalbumkey').val()==nid) return;
                    }
                    
                    $('.eediti').remove();
                    $('.sediti').removeClass();
                    $(this.parentNode).after("<tr class='eediti'><td colspan='6' class='editcontent'></td></tr>");
                    $(this.parentNode).addClass("sediti");
                    var url='controller/JO_ajax_navigation.php?SO_controller=SO_artistController&SO_action=loadeditalbum';
                    url+="&album="+nid;
                    $('.editcontent').html("<center><img src='JO_ICON/ajax-loader2.gif' alt=''/><center>");
                    
                    $('.editcontent').delay(5000).load(url,10000,
                        function(){
                            $("#btncancel").click(
                                function(){
                                    $('.eediti').remove();
                                    $('.sediti').removeClass();
                                }
                            );
                            $("#btnsave").click(
                                function(){
                                    var albumid=$('#txtalbumkey').val();
                                    var artistid=$('#txtartistkey').val();
                                    var albumtype=$('#cbxtype').val();
                                    var albumsubject=$('#txtsubject').val();
                                    var albumtrack=$('#txttrack').val();
                                    var albumimg=$('#txtimage').val();
                                    var albumrelease=$('#txtrelease').val();
                                    var albumcontent=$('#txtcontent').val();
                                    var surl='controller/JO_ajax_navigation.php';
                                    var sdata="";
                                    sdata+="SO_controller=SO_artistController&SO_action=savealbum";
                                    sdata+="&palbum="+albumid;
                                    sdata+="&partist="+artistid;
                                    sdata+="&ptype="+albumtype;
                                    sdata+="&psubject="+albumsubject;
                                    sdata+="&ptrack="+albumtrack;
                                    sdata+="&pimg="+albumimg;
                                    sdata+="&prelease="+albumrelease;
                                    sdata+="&pcontent="+albumcontent;
                                    //$('#txtcontent').val(surl+"?"+sdata);
                                    jQuery.ajax({
                                        type:"POST", //Phương thức gửi request là POST hoặc GET
                                        data:sdata, //tham số gửi kèm
                                        dataType:"text", //kiểu dữ liệu trả về, mặc định là text
                                        url:surl, //Đường dẫn tới nơi xử lý request ajax
                                        success: function (data){ //hàm gọi về khi thực hiện thành công
                                            // mã lệnh
                                            try {
                                                var getData = $.parseJSON(data);
                                                if(getData.nresult==0){
                                                    if($('#JO_errormsg').length){
                                                        $('#JO_errormsg').html("Error:"+getData.serrormsg);

                                                    }else{
                                                        //$('#JO_errormsg').remove();
                                                        $('#JO_beforeerrormsg').after("<tr ><td colspan='4' id='JO_errormsg'>Error:"+getData.serrormsg+"</td></tr>");
                                                        
                                                    }
                                                    $('#JO_errormsg').fadeOut(300).delay(500).fadeIn(300);
                                                }else{
                                                    
                                                    jQuery.ajax({

                                                        type:"POST", //Phương thức gửi request là POST hoặc GET
                                                        data:"SO_controller=SO_artistController&SO_action=getalbuminfo&palbum="+$('#txtalbumkey').val(), //tham số gửi kèm
                                                        dataType:"text", //kiểu dữ liệu trả về, mặc định là text
                                                        url:"controller/JO_ajax_navigation.php", //Đường dẫn tới nơi xử lý request ajax
                                                        success: function (dataresult){ //hàm gọi về khi thực hiện thành công
                                                            var getData = $.parseJSON(dataresult);
                                                            $($(".sediti").children('.tdsubjectalbum')).html(getData.ssubject);
                                                            $($(".sediti").children('.tdinsertalbum')).html(getData.dinsert);
                                                            $($(".sediti").children('.tdupdatealbum')).html(getData.dupdate);
                                                            $('.eediti').remove();
                                                            $('.sediti').removeClass();
                                                        },
                                                        error: function (){
                                                            alert('Có lỗi xảy ra');
                                                       }
                                                    });


                                                }
                                            } catch (exception) {

                                                if($('#JO_errormsg').length){
                                                    $('#JO_errormsg').html('');
                                                    $('#JO_errormsg').html("Error: I don't known this error. please check input data(incorrect data type).");

                                                }else{
                                                    $('#JO_beforeerrormsg').after("<tr ><td colspan='4' id='JO_errormsg'>Error: I don't known this error. please check input data(incorrect data type).</td></tr>");
                                                }
                                                $('#JO_errormsg').fadeOut(300).delay(500).fadeIn(300);
                                            }
                                        },
                                        error: function (){
                                            alert('Có lỗi xảy ra');
                                       }
                                    });

                                    


                                }
                            );
                        }
                    );

                }
            );
            }
            initeditalbum();
            $("#JO_getalbum").click(
                function(){
                    loadalbumpage(1);
                    
                }
            );
            function loadalbumpage(p){
                $('#JO_albumcontent').html("<center><img src='JO_ICON/ajax-loader2.gif' alt=''/><center>");
                var url='controller/JO_ajax_navigation.php?SO_controller=SO_artistController&SO_action=getalbum';
                url+="&subject="+$("#txtsename").val();
                url+="&key="+$("#txtsekey").val();
                url+="&bugs="+$("#txtsebugs").val();
                url+="&page="+p;
                $('#JO_albumcontent').load(url,function(){
                    //$.getScript("JO_IS/loadscript.js",function(){});
                    $(".tdactionalbum").click(
                        function(){
                            //alert($($(this.parentNode).children('.tdkeyalbum')).html());
                            //alsert($($(this.parentNode).children('.tdkeyalbum')).html());
                            
                            
                        }
                    );
                    initpageclick();
                    initeditalbum();
                });
                
            }
            function initpageclick(){
                $(".JO_pagesi").click(
                    function(){
                        loadalbumpage($(this).html());
                    }
                );
            }
            initpageclick();
            

        </script>
    </div>
</div>
<!--<div style="
     position: fixed;
     top: 50%;left: 50%;
     background: red;
     margin-left: -200px;margin-top: -200px;
     width: 400px;height: 400px;
     *position: absolute;
     *top: expression(50+((e=document.documentElement.scrollTop)?e:document.body.scrollTop)+'px');
    
     
     ">
    <div style="width: 400px;height: 200px;background: blue">
        asds
    </div>

</div>-->